/*
 * Utils.h
 *
 * These are the general utility functions (like printing vectors etc.,) which are used in most situations.
 *
 *
 *  Created on: Oct 1, 2009
 *      Author: karthik
 */

#ifndef UTILS_H_
#define UTILS_H_

#include<iostream>
#include<string>
#include<sstream>
#include <vector>

#include "tnt_jama/tnt.h"

//using namespace JAMA;  // JAMA and TNT are defined in namespaces.
using namespace TNT;  // without the "using" statement we would have to write JAMA:: or TNT::

using namespace std;

//	Function for printing an Array2D object
void printArray2D(const Array2D<double>& X);

// Function for splitting a string using a delimiter
void StringSplit(std::string str, std::string delimiter, std::vector<std::string>& );

// Function for printing an object of type vector<double>
void printVofDouble(const std::vector<double>& vect);

//	Template function to convert objects of types like double, int etc., to string type
//	Mainly used for outputting to a text file.
template<class T>
    std::string toString(const T& t)
{
     std::ostringstream stream;
     stream << t;
     return stream.str();
}

//	Template function to convert string type objects to objects of types like double, int etc.,
//	Mainly used for reading from a text file.
template<class T>
    T fromString(const std::string& s)
{
     std::istringstream stream (s);
     T t;
     stream >> t;
     return t;
}

#endif /* UTILS_H_ */
